import {createRouter, createWebHistory} from "vue-router"

import HomeView from "../components/home.vue"
// import AboutView from "../views/AboutView.vue"


const routes = [
    // path 必填字段，component 必填字段，name 非必填字段，路由名字，建议加上
    // 通过懒加载方式注册组件
    // {path: "/login", component: () => import("../components/login/login.vue"), name: "login"},
    { path: '/', redirect: '/index' },
    {
        name: 'index', 
        path: '/index', 
        component: () => import("../components/index.vue"), 
        redirect: '/index/diff', 
        children: [
          { name: 'home', path: 'home', component: HomeView },
          //   rdp管理1
          {
            name: 'diff', path: 'diff', component: () => import("../components/diffs/diff.vue"), 
          },
          {
            name: 'edit', path: 'edit', component: () => import("../components/edit/edit.vue"), 
          },
        ]
      },
]


const router = createRouter({
    // createWebHashHistory    这种路径里面会有井号 # 出现，
    // createWebHistory        此种方式需要后台做重定向，否则会出现404
    history: createWebHistory('/config/'),
    routes
})

// // 全局路由导航守卫
// router.beforeEach((to, from, next) => {
//     // 判断是否为登录页面，是则放行
//     // console.log('xxxxxxxx', to.path);
//     // console.log('bbbbbbbb')
//     if (to.path === '/login' || to.path === '/jwt') return next()
//     // 获取 token 值
//     const auth = localStorage.getItem('auth')
//     // console.log("是否有token:", token);
//     // 如果 token 不存在，跳转到登录页面
//     if (!auth) {
//       return next('/login')
//       // console.log('xxxxxxxx222', to.path);
//     }
//     // token 存在，直接放行
//     next()
// })

export default router;